package com.hanrui.android.fragment.message.threesupervise;

import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.hanrui.android.R;
import com.hanrui.android.adapter.ThreeSuperviseLcAdapter;
import com.hanrui.android.library.base.BaseFragment;
import com.hanrui.android.model.ThreeSuperviseDetailBean;
import com.hanrui.android.net.contract.message.threesupervise.ThreeSuperviseDetailContract;
import com.hanrui.android.net.presenter.message.threesupervise.ThreeSuperviseDetailtPresenter;

import butterknife.BindView;

/**
 * 督办审批流程图
 *
 */

public class ThreeSuperviseLcFragment extends BaseFragment<ThreeSuperviseDetailtPresenter> implements ThreeSuperviseDetailContract.View{

    @BindView(R.id.recyclerview_swipeLayout)
    SwipeRefreshLayout swipeLayout;
    @BindView(R.id.recyclerview)
    RecyclerView mRecyclerView;

    ThreeSuperviseLcAdapter adapter;

    String id;

    @Override
    protected int getLayoutId() {
        return R.layout.swipe_recyclerview;
    }

    @Override
    protected void initInjector() { mFragmentComponent.inject(this); }

    @Override
    protected void initView(View view) { init(); }


    public void init() {

        id = getArguments().getString("id");

        swipeLayout.setColorSchemeColors(ContextCompat.getColor(getActivity(),R.color.c_2795ff));
        swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {

                mPresenter.overSeeThreeDetail(getActivity(),id);

            }

        });

        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        adapter = new ThreeSuperviseLcAdapter();
        mRecyclerView.setAdapter(adapter);

        swipeLayout.setRefreshing(true);
        mPresenter.overSeeThreeDetail(getActivity(),id);

    }


    public static ThreeSuperviseLcFragment newInstance(String id) {
        ThreeSuperviseLcFragment fragment = new ThreeSuperviseLcFragment();
        Bundle bundle = new Bundle();
        bundle.putString("id", id);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void overSeeThreeDetail(ThreeSuperviseDetailBean data) {

        swipeLayout.setRefreshing(false);

        if (null != data && data.getThreeColorDetailList().size() > 0) {

            adapter.setNewData(data.getThreeColorDetailList());


        		}


    }
}
